package com.cjw.campus.system.controller;

import com.cjw.campus.core.result.JsonResult;
import com.cjw.campus.system.entity.QuestionsTable;
import com.cjw.campus.system.entity.SubjectTable;
import com.cjw.campus.system.service.ISubjectTableService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 学科表 前端控制器
 * </p>
 *
 * @author cjw
 * @since 2023-02-28
 */
@RestController
@RequestMapping("/system/subjectTable")
@Tag(name = "学科管理接口")
public class SubjectTableController {

    @Autowired
    private ISubjectTableService subjectTableService;

    @GetMapping("/list")
    @Operation(summary = "查询所有学科", security = { @SecurityRequirement(name = "Authorization")})
    public JsonResult list () {
        List<SubjectTable> list = subjectTableService.list();
        return JsonResult.ok(list);
    }

    @PostMapping("/save")
    @Operation(summary = "保存学科", security = { @SecurityRequirement(name = "Authorization")})
    @Parameter(name = "subjectTable")
    public JsonResult save (@RequestBody SubjectTable subjectTable) {
        // 保存年级信息
        boolean save = subjectTableService.save(subjectTable);
        // 判断年级是否新增成功
        if (save) {
            // 成功返回
            return JsonResult.ok();
        }
        // 失败返回
        return JsonResult.error("新增失败");
    }

}
